<?php

class SiteController extends Controller
{
	
	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex()
	{
		$model = new Article;
		$data=  $model->Page();
		$this->render('index',array('data'=>$data));
	}

	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError()
	{
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}

	public function actionSiteMap()
	{
		Yii::app()->clientScript->reset();
		$this->layout=".";
		$cache =Yii::app()->cache;
		$list= $cache->get("sitemap");
		if ($list===false) {
			$list =  Yii::app()->db->createCommand()
				->select('a.id,a.createtime')
				->from('edu_article a')
				->where('status=:status',array(':status'=>200))
				->order('createtime  desc')
				->queryAll();
			$cache->set("sitemap",$list,3600);
		}
		header("Content-type: text/xml");
		echo '<?xml version="1.0" encoding="UTF-8"?>';
		$this->render('sitemap',array('list'=>$list));
	}
}